//
//  AppConfig.swift
//  Example
//
//  Created by remy on 2019/3/26.
//  Copyright © 2019 com.Risac. All rights reserved.
//

class AppConfig {
    public static var testMode: Bool = false // 是否测试模式
    public static var debugPack: Bool { // 是否debug包
        #if DEBUG
            return true
        #else
            return false
        #endif
    }
    public static var releaseEnvironment: Bool { // 线上环境,release包且关闭测试模式
        return !debugPack && !testMode
    }
    
    static func set() {
        // SwiftDate
        SwiftDate.defaultRegion = Region.local
        // 分隔线默认设置
        ViewLineType.tintColor = FlatColor.silver
        // 控制器默认设置
        BaseVC.global.bgColor = FlatColor.clouds
        BaseVC.global.leftBackItem = .text("back") {
            $0.inset(UIEdgeInsets(top: 0.0, left: 16.0, bottom: 0.0, right: 8.0))
        }
        BaseVC.global.leftCancelItem = .text("cancel") {
            $0.inset(UIEdgeInsets(top: 0.0, left: 16.0, bottom: 0.0, right: 8.0))
        }
        // 导航栏默认设置
        RisacTopBar.global.bgColor = .white
        RisacTopBar.global.textColor = (FlatColor.midnightBlue, FlatColor.midnightBlue, FlatColor.midnightBlue)
        RisacTopBar.global.lineColor = FlatColor.midnightBlue
        RisacTopBar.global.viewHeight = Size.topBarHeight
        // 刷新默认设置
        RefreshComponent.defaultPullingText = ["下拉可以刷新", "上拉可以刷新"]
        RefreshComponent.defaultReleaseToRefreshText = "松开立即刷新"
        RefreshComponent.defaultLoadMoreText = ["下拉加载数据", "上拉加载数据"]
        RefreshComponent.defaultNoMoreDataText = "没有更多内容啦"
        RefreshComponent.defaultRefreshingText = "正在刷新数据中..."
        RefreshComponent.defaultLoadingText = "正在加载数据中..."
        // webView进度条默认设置
        RisacWebViewProgress.tintColor = FlatColor.belizeHole
        // 选择器默认配置
        RisacPicker.global.bgColor = .white
        RisacPicker.global.titleBarTextColor = FlatColor.midnightBlue
        // 网络请求默认设置
        NetworkManager.global.needSuccessProcess = true
        NetworkManager.global.responseSuccessProcess = { (_, _) in
            Risac.print("responseSuccessProcess!!!!!!")
        }
        DataLoader.defaultStartPageInfo = (1, 15)
        // 弹出层默认设置
        RisacPop.global.solo = false
        RisacPop.global.stage = .window(false)
        RisacPop.global.stayTime = 3.0
        RisacMask.global.solo = false
        RisacMask.global.stage = .window(false)
        // 开启键盘监听
        KeyboardManager.shared.enabled = true
    }
}

public struct FlatColor {
    /// 0x1ABC9C,青绿色-浅
    public static let turquoise = UIColor(0x1ABC9C)
    /// 0x16A085,青绿色-深
    public static let greenSea = UIColor(0x16A085)
    /// 0x2ECC71,翠绿色-浅
    public static let emerald = UIColor(0x2ECC71)
    /// 0x27AE60,翠绿色-深
    public static let nephritis = UIColor(0x27AE60)
    /// 0x3498DB,蓝色-浅
    public static let peterRiver = UIColor(0x3498DB)
    /// 0x2980B9,蓝色-深
    public static let belizeHole = UIColor(0x2980B9)
    /// 0x9B59B6,紫色-浅
    public static let amethyst = UIColor(0x9B59B6)
    /// 0x8E44AD,紫色-深
    public static let wisteria = UIColor(0x8E44AD)
    /// 0x34495E,深蓝色-浅
    public static let wetAsphalt = UIColor(0x34495E)
    /// 0x2C3E50,深蓝色-深
    public static let midnightBlue = UIColor(0x2C3E50)
    /// 0xF1C40F,橘黄色-浅
    public static let sunflower = UIColor(0xF1C40F)
    /// 0xF39C12,橘黄色-深
    public static let orange = UIColor(0xF39C12)
    /// 0xE67E22,橘红色-浅
    public static let carrot = UIColor(0xE67E22)
    /// 0xD35400,橘红色-深
    public static let pumpkin = UIColor(0xD35400)
    /// 0xE74C3C,红色-浅
    public static let alizarin = UIColor(0xE74C3C)
    /// 0xC0392B,红色-深
    public static let pomegranate = UIColor(0xC0392B)
    /// 0xECF0F1,灰白色-浅
    public static let clouds = UIColor(0xECF0F1)
    /// 0xBDC3C7,灰白色-深
    public static let silver = UIColor(0xBDC3C7)
    /// 0x95A5A6,灰色-浅
    public static let concrete = UIColor(0x95A5A6)
    /// 0x7F8C8D,灰色-深
    public static let asbestos = UIColor(0x7F8C8D)
    static func randomColor(_ index: Int? = nil) -> UIColor {
        let colors: [UIColor] = [peterRiver, emerald, amethyst, sunflower, alizarin, concrete, carrot]
        if let index = index {
            return colors[index % colors.count]
        }
        return colors[Int(arc4random()) % colors.count]
    }
}
